var api = require('../../../utils/api.js')
var $ = require('../../../utils/util.js')
var regeneratorRuntime = require('../../../utils/runtime.js')
var app = getApp()


Page({

  data: {
    statusBarHeight: 0, // 状态栏高度 
    hasMore: true,// 判断 数据是否全部加载完
    isLodingLock: true, //锁 防止数据加载
    pageNum: 1, //页码
    isShowKong: false, // 是否是空
    keyword:'', // 搜索关键字 
    pageList:[]
  },
  onLoad: function (options) {
    this.getPagServer(1, true) //获取分页数据  
  },
  onShow: function () {
    // this.getPagServer(1, true) //获取分页数据  
  },
  showVideo: function(e){
    var {item} = $.detail(e)
    wx.setStorageSync("videoInfo",item);
    // $.linkurl(`/pages/onlineVideo/onlineVideoPlay/onlineVideoPlay?info=${JSON.stringify(item)}`)
    $.linkurl(`/pages/onlineVideo/onlineVideoPlay/onlineVideoPlay`)

  },
  handleVideo: function(e){
    var {item} = $.detail(e)
    $.linkurl('/pages/onlineVideo/videoPages/live/live?accessToken=' + item.access_token + '&deviceSerial='+ item.deviceSerial + '&channelNo=' + item.channelNo+'&factory='+item.factory+'&video_name='+item.video_name+'&appKey='+item.appKey+'&appSecret='+item.appSecret+'&location='+item.location)
  },
  onReachBottom() { //滑动到底部触发
    this.loadingMore()
  },
  onPullDownRefresh: function () { // 下拉刷新
    this.getPagServer(1, true) //获取分页数据
  },


  loadingMore: function () {  // 加载更多
    console.log(this.data.isLodingLock, 111)
    if (this.data.isLodingLock) {
      this.setData({
        isLodingLock: false
      })

      this.getPagServer()
    }
  },

  getPagServer(pageNum, isClickTab = false) { //分页  
    var params = {
      pageNum: pageNum == 1 ? 1 : this.data.pageNum,
      pageSize: 10,
      keyword: this.data.keyword
    } 
    $.getPageList(api, this,  api.onlineVideo.list, params, isClickTab).then((res) => {
      wx.stopPullDownRefresh() // 接口数据请求完停止刷新
    })
  },

  //##input 输入##
  input_handle(e) {
    this.setData({
      [e.currentTarget.dataset.key]: e.detail.value
    })
  },
  //##input 输入##

  search(){ // 搜索输入框 
    if($.isNull(this.data.keyword)){
      $.toast('请输入内容') 
    }else {
      this.getPagServer(1, true) //获取分页数据
    }

  },
})
